package Code.Basic.AI.Pathfinding;

import java.awt.geom.GeneralPath;

import org.jrabbit.base.graphics.transforms.Vector2d;

public class ZoneGeometry
{
	private Vector2d center;
    protected GeneralPath shape;
    
	public ZoneGeometry(double[][] vertices)
	{
		shape = new GeneralPath();
		setShape(vertices);
	}
	
	public void setShape(double[][] vertices)
    {
    	shape = new GeneralPath();
    	
    	double x = vertices[0][0];
    	double y = vertices[0][1];
    	
    	shape.moveTo(x, y);
    	for(int i = 1; i < vertices.length; i++)
    	{
    		x += vertices[i][0];
    		y += vertices[i][1];
    		shape.lineTo(vertices[i][0], vertices[i][1]);
    	}
    	shape.closePath();
    	
    	center = new Vector2d(x / vertices.length, y / vertices.length);
    }
	
	public Vector2d location()
	{
		return center;
	}
	
	public boolean containsPoint(Vector2d point)
    {
    	if(shape.getBounds2D().contains(point.x(), point.y()))
    	{
    		return shape.contains(point.x(), point.y());
    	}
		return false;
    }
}